package n344;

/**
 * @author 苏文广
 * @since 2021/10/3
 */
public class TwoPointSolution {
    // 双指针
    public static void main(String[] args) {
        TwoPointSolution twoPointSolution = new TwoPointSolution();
        char[] s = {'h', 'e', 'l', 'l', 'o'};
        twoPointSolution.reverseString(s);
        System.out.println(s);
    }

    public void reverseString(char[] s) {
        if (s==null || s.length <= 1){
            return;
        }

        // 反向双指针
        int left = 0;
        int right = s.length - 1;

        while (left < right){
            char temp = s[left];
            s[left] = s[right];
            s[right] = temp;
            left ++;
            right --;
        }
    }
}
